<?php
namespace app\event;
use think\facade\Response;

class CORS
{
    public function handle()
    {

//        header("Access-Control-Allow-Origin: *");   //全域名
//        header("Access-Control-Allow-Credentials: true");   //是否可以携带cookie
//
//        header("Access-Control-Allow-Methods: POST,GET,PUT,OPTIONS,DELETE");   //允许请求方式
//        header("Access-Control-Allow-Headers: X-Custom-Header");   //允许请求字段，由客户端决定
//        header("Content-Type: text/html; charset=utf-8"); //返回数据类型（ text/html; charset=utf-8、 application/json; charset=utf-8 )
        header('Access-Control-Allow-Origin:*');
//json头
        header("Content-type: application/json");
//跨域
        header("Access-Control-Allow-Credentials: true");
//header("Access-Control-Allow-Origin: 跨域URL");
//CORS
        header("Access-Control-Request-Methods:GET, POST, PUT, DELETE, OPTIONS");
        header('Access-Control-Allow-Headers:x-requested-with,content-type,test-token,test-sessid,token,appid,appkey');//注意头部自定义参数不要用下划线

        if(request()->isOptions()){
            echo 'dsfade';
            exit();
        }
    }
}
